﻿using System;
using StackExchange.Redis.Extensions.Core;
using StackExchange.Redis.Extensions.Newtonsoft;

namespace RedisDemo
{
    public class User
    {
        public string Firstname { get; set; }
        public string Lastname { get; set; }
        public string Twitter { get; set; }
        public string Blog { get; set; }
    }
    class Program
    {
        static void Main(string[] args)
        {
            //ConnectionMultiplexer redis = ConnectionMultiplexer.Connect("127.0.0.1:6379");
            //IDatabase db = redis.GetDatabase();

            //string value = "abcdefg";
            //db.StringSet("mykey", value);

            //string value2 = db.StringGet("mykey");
            //Console.WriteLine(value2); // writes: "abcdefg"

            var serializer = new NewtonsoftSerializer();
            var myCacheClient = new StackExchangeRedisCacheClient(serializer);

            var user = new User()
            {
                Firstname = "Ugo",
                Lastname = "Lattanzi",
                Twitter = "@imperugo",
                Blog = "http://tostring.it"
            };
            bool added = myCacheClient.Add("my cache key", user, DateTimeOffset.Now.AddMinutes(10));

            var cachedUser = myCacheClient.Get<User>("my cache key");

            Console.ReadKey();

        }
    }
}
